import request from '../utils/request'

export const listQuestions = (currentPage, pageSize, order) => {
	return request({
		url: `/questions?offset=${currentPage}&limit=${pageSize}&order=${order}`,
		method: 'GET',
	})
}

export const listQuestionsByState = (currentPage, pageSize, state, sorter) => {
	return request({
		url: `/questions?offset=${currentPage}&limit=${pageSize}&state=${state}&order=${sorter}`,
		method: 'GET',
	})
}

export const listQuestionsByKeyword = (
	currentPage, pageSize, order, keyword) => {
	return request({
		url: `/questions?offset=${currentPage}&limit=${pageSize}&order=${order}&keyword=${keyword}`,
		method: 'GET',
	})
}

export const listQuestionsByUserId = (currentPage, pageSize, userId) => {
	return request({
		url: `/questions?offset=${currentPage}&limit=${pageSize}&userId=${userId}`,
		method: 'GET',
	})
}

export const insertQuestion = (questionDTO) => {
	return request({
		url: '/questions',
		method: 'POST',
		data: questionDTO,
	})
}

export const deleteQuestion = (questionId) => {
	return request({
		url: `/questions/${questionId}`,
		method: 'DELETE',
	})
}

export const partialUpdateQuestion = (questionId, questionDTO) => {
	return request({
		url: `/questions/${questionId}`,
		method: 'PATCH',
		data: questionDTO,
	})
}

export const partialUpdateQuestionList = (questionIds) => {
	return request({
		url: '/questions',
		method: 'PATCH',
		data: questionIds,
	})
}

export const getQuestion = (questionId) => {
	return request({
		url: `/questions/${questionId}`,
		method: 'GET',
	})
}

export const listQuestionsByTagId = (currentPage, pageSize, id, tab) => {
	return request({
		url: `/questions/tags/${id}?offset=${currentPage}&limit=${pageSize}&tab=${tab}`,
		method: 'GET',
	})
}

